<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <script src="__STATIC__/index/js/global/jquery-3.2.1.min.js"></script>
</head>
<body>
    <form action="javascript:;" method="post">
        <input type="text" name="auth_code" value="" onchange="check_form()">
        <input type="text" name="order_sn" value="{$order_sn}" >
    </form>
</body>
</html>
<script>
  function check_form(){
      var auth_code = $('input[name=auth_code]').val();
      var order_sn = $('input[name=order_sn]').val();
      $.post("{:url('Wxpay/pay')}",
          {auth_code:auth_code,order_sn:order_sn},
          function(data){

          }
      );
  }

  //执行轮询 -- 查询支付结果进行跳转
//  setInterval(function(){
//      get_result();
//  },4000);
  /**
   * 查询订单结果
   */
  function get_result(){
      var order_sn = $('input[name=order_sn]').val();
      $.post("{:url('Wxpay/get_result')}",
          {order_sn:order_sn},
          function(data){
              if(data.code == 1){
                  alert('支付成功');
                  console.log(data);
              }else{
                  console.log(data);
              }
          }
      );
  }
</script>